#ifndef M_PHONG
#define M_PHONG
#include"BxDF.h"
class PhongReflection : public BxDF
{
#define DEFAULT_PHONG_N 20
#define DEFAULT_DIVIDED 0
private:
	int n; //coefficient
	bool divide_by_NdotL;
public:
	PhongReflection(int _n = DEFAULT_PHONG_N, int _divided_by_NL = DEFAULT_DIVIDED) :n(_n), divide_by_NdotL(_divided_by_NL), BxDF(BxDFType(BSDF_GLOSSY | BSDF_REFLECTION)) {}
	virtual Spectrum f(P3 &light, P3 &view)
	{
		P3 R = -light.localReflect();

		// specular
		Float RV = R.dot(view);
		if (RV < 0) return Spectrum();
		Float val = pow(RV, n);
		if (divide_by_NdotL)
			val = val / light.z;
		Float rgb[] = { val,val,val };
		return Spectrum::FromRGB(rgb, SpectrumType::Reflectance);
	}
};
#endif // !M_PHONG

